package com.zzl.mine.util;


import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;

import javax.imageio.ImageIO;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;

public class QRUtil {
	private static final String CODE = "utf-8";
	private static final int BLACK = 0xff000000;
	private static final int WHITE = 0xFFFFFFFF;

	static Logger logger = Logger.getLogger(QRUtil.class);

	/**
	 * 生成QR二维码
	 * 
	 * @param str
	 *            内容
	 * @param height
	 *            高度（px）
	 * @return
	 */
	public static BufferedImage getQR(String str, Integer height) {
		if (height == null || height < 100) {
			height = 200;
		}
		try {
			// 文字编码
			Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
			hints.put(EncodeHintType.CHARACTER_SET, CODE);
			hints.put(EncodeHintType.MARGIN, 1); /* default = 4 */
			BitMatrix bitMatrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, height, height, hints);
			return toBufferedImage(bitMatrix);
			// ImageIO.write(image, "png", response.getOutputStream());// 输出方式
			// 网页
			// ImageIO.write(image, "png", file);// 输出方式 文件
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 生成二维码，写到文件中
	 * 
	 * @param str
	 * @param height
	 * @param file
	 * @throws IOException
	 */
	public static void getQRWriteFile(String str, Integer height, File file) throws IOException {
		BufferedImage image = getQR(str, height);
		ImageIO.write(image, "png", file);
	}

	/**
	 * 转换成图片
	 * 
	 * @param matrix
	 * @return
	 */
	private static BufferedImage toBufferedImage(BitMatrix matrix) {
		int width = matrix.getWidth();
		int height = matrix.getHeight();
		BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
			}
		}
		return image;
	}

	/**
	 * 解码(二维、一维均可)
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static String read(File file) {
		BufferedImage image;
		try {
			if (file == null || file.exists() == false) {
				throw new Exception(" File not found:" + file.getPath());
			}

			image = ImageIO.read(file);

			LuminanceSource source = new BufferedImageLuminanceSource(image);
			BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

			Result result;

			// 解码设置编码方式为：utf-8，
			Hashtable hints = new Hashtable();
			hints.put(DecodeHintType.CHARACTER_SET, "utf-8");

			result = new MultiFormatReader().decode(bitmap, hints);

			return result.getText();
		} catch (Exception e) {
			e.printStackTrace();
		}

		return null;
	}

	private static String getImageBinary(BufferedImage bi) {
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ImageIO.write(bi, "png", baos);
			byte[] bytes = baos.toByteArray();

			return Base64.encodeBase64String(bytes).trim();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void base64StringToImage(String base64String, String path) {
		try {
			byte[] bytes1 = Base64.decodeBase64(base64String);
			ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);
			BufferedImage bi1 = ImageIO.read(bais);
			File w2 = new File(path);// 可以是jpg,png,gif格式
			ImageIO.write(bi1, "png", w2);// 不管输出什么格式图片，此处不需改动
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String getQrBase64String(String str, int height) {
		BufferedImage image = getQR(str, height);
		if (image == null)
			return null;
		String base64Str = getImageBinary(image);
		return base64Str;
	}

	public static String getLogoQrBase64String(String str, int height, String logoPath) {
		BufferedImage image = getQR(str, height);
		if (image == null)
			return null;

		try {
			Graphics2D gs = image.createGraphics();

			// 载入logo
			Image img = ImageIO.read(new File(logoPath));
			gs.drawImage(img, (image.getWidth() - 64) / 2, (image.getHeight() - 64) / 2, null);

			gs.dispose();
			img.flush();
		} catch (Exception e) {
			//logger.error(e.getMessage(), e);
		}

		String base64Str = getImageBinary(image);
		return base64Str;
	}

	@SuppressWarnings("unused")
	public static String getLogoQrTextBase64String(String str, String amountStr, String reson, String logoPath,
			int height, int qrHeight) {
		try {
			BufferedImage qrimage = getQR(str, qrHeight);
			if (qrimage == null)
				return null;

			BufferedImage image = new BufferedImage(height, height, BufferedImage.TYPE_INT_RGB);
			Graphics2D gs = image.createGraphics();
			gs.setBackground(Color.WHITE);
			gs.fillRect(0, 0, height, height);

			// String base64String =
			// "iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAYAAACAvzbMAAAUtUlEQVR42u3dX4xcVR0H8BKggkUfIFFIDFFEMOHJqvgn+sQDEo0mkgiJmCAEiQoPPvgnamLCk8ZEjL74QIxBKO1ud7bb8qc2WLBAKP1HQSxCafnbFqSwpe3SP8v2552duzLBvbOzszOde+58vsnJJpQ9e+895/w+M3dmziwKERGRDrLIJRAREYCIiAhAREQEICIiAhARERGAiIgIQEREBCAiIgIQEREBiIiICEBERAQgIiICEBERAYiIiABEREQEICIiAhAREakIIIsWLdLm2UoxAXp0vKn1W+WxqPLxqiP9rTsAAQhAAAIQdQcgAAEIQACiAcRAAgQgAFF3AKIBBCAAAQhADCRAAAIQgKg7AAEIQAACEHUHIAYSIAABiAYQAwkQgABE3QGIBhCAAAQgADGQAAEIQACi7pQAkCpHQS7P9TUnoWuMAWIgAQIQa1PdAYiBBAhAFFnnBhADCRCAKC7ODSAGEiAAMScBYowBAhCAAAQgxhggBhIgALE21R2AGEiAAESRdW4AMZAAAYg56dxcB4AABCDmJECMMUAAAhCAAMQYA+QkFAwFufqQ2qup+ns1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FAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEM3EAwhAAAIQgAAEIAABiHVcAkCqHNchzQVY5XEDqQfEldoLS+F0HQACEIAAROF0HQBiTgIEIAqn6wAQgFgXAAEIQAACEIAABCAWq+sAEIAABCAKp+sAEIAABCAKp+sAEHMSIABROAECEIAABCAAsVgBAhCAAAQgCqfrABCAAAQgg1Mw7KFTnuO1N5qC7AFFj8cVIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACEIAAxL5Oqc/1ShcltQQgAAEIQACilgDEoAMEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhAAKKWAAQgAAEIQNQSgBh0gAAEIAABCEAAAhCAAAQgAAEIQAACEIAABCAAAQhA1BKAGPSqF5cq72dkPqT5QMUY9xcmgJhMADEfAGLNA8RkAoj5ABBjDBCAAAQgAAEIQAACEIAABCAAAQhANIAABCAAMZkAYj4AxJoHiIIBEPMBIMYYIAABCEAAAhCAAAQgAAEIQAACEJMJIAABCEASAyS1KBjlGWNzsvpjXOUHS0lcJ4sVIAAxJwECEIAABCDmJEAAAhCAAMScBAhAAGLiAQQgAHHNAGKxAgQgiqFrBhCAAAQg5iRAAAIQgADEnAQIQAACEICYkwABCEBMPIAABCCuGUAsVoAARDF0zQDSf0C0NPcEg43r65ql/6ARICapAqcYAgQgAAGI6wsQgAAEIBpAAAIQaxMgJhNAAOL6umYAAQhAAOL6umYAAYhJqsAphgABCEA01xcgAAEIQAACEIAAxNoEiMkEEIC4vq4ZQAACEIC4vgABSAKAiIjIYAUgIiICEBERAYiIiABEREQAIiIiAhAREQGIiIgAREREACIiIgAREREBiIiIAERERAAiIiIAERERgIiIiABEREQAIiIiABERkRTzX2VQWD/vfIv6AAAAAElFTkSuQmCC";
			//
			// byte[] bytes1 = Base64.decodeBase64(base64String);
			// ByteArrayInputStream bais = new ByteArrayInputStream(bytes1);
			//
			// Image img = ImageIO.read(bais);
			//
			gs.drawImage(qrimage, (height - qrHeight) / 2, (height - qrHeight) / 2, null);

			gs.setColor(Color.BLACK);
			Font font = new Font("simsun", Font.BOLD, 40);
			gs.setFont(font); // 字体、字型、字号
			// Rectangle clip = gs.getClipBounds();
			FontMetrics fm = gs.getFontMetrics(font);
			if (StringUtils.isNotEmpty(amountStr)) {
				int textWidth = fm.stringWidth(amountStr);
				int x = (height - textWidth) / 2;
				int ascent = fm.getAscent();
				int descent = fm.getDescent();
				int y = 40;
				gs.drawString(amountStr, x, y); // 画文字
			}

			font = new Font("simsun", Font.PLAIN, 24);
			gs.setFont(font); // 字体、字型、字号

			fm = gs.getFontMetrics(font);
			if (StringUtils.isNotEmpty(reson)) {
				int textWidth = fm.stringWidth(reson);
				int x = (height - textWidth) / 2;
				int ascent = fm.getAscent();
				int descent = fm.getDescent();
				int y = height - 40;
				gs.drawString(reson, x, y); // 画文字
			}

			if (StringUtils.isNotEmpty(logoPath)) {
				// 载入logo
				Image img = ImageIO.read(new File(logoPath));
				gs.drawImage(img, (image.getWidth() - 64) / 2, (image.getHeight() - 64) / 2, null);
			}

			gs.dispose();

			String base64Str = getImageBinary(image);
			return base64Str;
		} catch (Exception e) {
			//logger.error(e.getMessage(), e);
			return null;
		}
	}

	@SuppressWarnings("unused")
	public static void getQRWriteFile(String str, String logoPath, File file, int height, int qrHeight) {
		try {
			BufferedImage qrimage = getQR(str, qrHeight);
			BufferedImage image = new BufferedImage(height, height, BufferedImage.TYPE_INT_RGB);
			Graphics2D gs = image.createGraphics();
			gs.setBackground(Color.WHITE);
			gs.fillRect(0, 0, height, height);
			gs.drawImage(qrimage, (height - qrHeight) / 2, (height - qrHeight) / 2, null);
			gs.setColor(Color.BLACK);
			Font font = new Font("simsun", Font.BOLD, 40);
			gs.setFont(font); // 字体、字型、字号
			FontMetrics fm = gs.getFontMetrics(font);
			font = new Font("simsun", Font.PLAIN, 24);
			gs.setFont(font); // 字体、字型、字号
			fm = gs.getFontMetrics(font);
			if (StringUtils.isNotEmpty(logoPath)) {
				// 载入logo
				Image img = ImageIO.read(new File(logoPath));
				gs.drawImage(img, (image.getWidth() - 64) / 2, (image.getHeight() - 64) / 2, null);
				gs.dispose();
				img.flush();
			}
			ImageIO.write(image, "png", file);
		} catch (Exception e) {

		}
	}

	public static void main(String[] args) {
		/*
		 * 生成二维码
		 * File file = new File("d:\\kevin.png");
		try {
			QRUtil.getQRWriteFile("https://qr.alipay.com/baxce1rkqg0rf8qxe0",200,file);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		
//		alipay-random-->HTTPS://QR.ALIPAY.COM/FKX08612M4LD5UOFN3RQE3
//		alipay-fasten-->HTTPS://QR.ALIPAY.COM/FKX09803FRRASW8IUGDYD7
//		weixin_random-->wxp://f2f0gs7G0HSuhR2m0bBZSMZAU29QmlDUxR6o
//		weixin_fasten-->wxp://f2f1WW5Ty5o8K55EJQsF9SEWvVKdTMwFoO0Y
//		union_fasten-->https://qr.95516.com/00010000/62121273457306804961573539024510
//		union_random-->https://qr.95516.com/00010000/62020725163075683975547506020659
	
//		File file = new File("d:\\490690460908941584.jpg");
		File alipay_random = new File("d:\\alipay-random.png");
//		File alipay_fasten = new File("d:\\alipay-fasten.jpg");
//		File alipay_fasten = new File("f:\\575780341424376600.jpg");
		File alipay_fasten = new File("d:\\716927865268762023.jpg");
		File weixin_random = new File("d:\\weixin-random.png");
		File weixin_fasten = new File("d:\\weixin-fasten.png");
		File union_fasten = new File("d:\\union_fasten.png");
		File union_random = new File("d:\\union_random.png");
		
		System.out.println("alipay-random-->"+QRUtil.read(alipay_random));
		System.out.println("alipay-fasten-->"+QRUtil.read(alipay_fasten));
		
		
		System.out.println("weixin_random-->"+QRUtil.read(weixin_random));
		System.out.println("weixin_fasten-->"+QRUtil.read(weixin_fasten));
		
		
		System.out.println("union_fasten-->"+QRUtil.read(union_fasten));
		System.out.println("union_random-->"+QRUtil.read(union_random));
		
		 
		 
		/*
		String amountStr = "¥10.00";
		String reson = "消费";
		String srt = QRUtil.getLogoQrTextBase64String(str, amountStr, reson, "D://qrIcon.png", 500, 400);
		System.out.println("srt-->"+srt);
	
		*/
	}

}
